package edu.njfu.mystudentapp.adapter


import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import edu.njfu.mystudentapp.R
import edu.njfu.mystudentapp.model.Info


import kotlinx.android.synthetic.main.student_info_item.view.*

class InfoAdapterByRecyclerView (val studentInfo:List<Info>):
    RecyclerView.Adapter<InfoAdapterByRecyclerView.ViewHolder>() {
    inner class ViewHolder(view: View):RecyclerView.ViewHolder(view){
        var stutype:TextView=view.findViewById(R.id.studenName)
        var stuValue:TextView=view.findViewById(R.id.studentNumber)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view= LayoutInflater.from(parent.context)
            .inflate(R.layout.student_info_item,parent,false)
        var viewHolder=ViewHolder(view)
        return  viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var info=studentInfo[position]
       holder.stutype.text=info.type.toString()
        holder.stuValue.text=info.value.toString()
    }

    override fun getItemCount(): Int {
        return studentInfo.size
    }
}